import 'package:flutter/material.dart';
import 'package:flutter_worker730/utils/PromptAction.dart';
import 'package:flutter_worker730/utils/TokenManager.dart';
import 'package:shared_preferences/shared_preferences.dart';

// 无状态组件 只是显示数据  不负责修改数据
// 无状态组件 没有this.context 只能通过build传递context
class HomeNav extends StatelessWidget {
  HomeNav({Key? key}) : super(key: key);

  // 导航数据
  // 程序员 必须有一个能力 抽象出对象的能力  万物皆对象
  final List navList = [
    {
      'title': '我的房屋',
      'icon': '/images/house_nav_icon@2x.png',
    },
    {
      'title': '我的报修',
      'icon': '/images/repair_nav_icon@2x.png',
    },
    {
      'title': '访客登记',
      'icon': '/images/visitor_nav_icon@2x.png',
    }
  ];
  Widget getBottom() {
    return Container(
      width: double.infinity,
      height: 200,
      color: Colors.red,
      child: Column(
        children: [
          Text('1'),
          Text('1'),
          Text('1'),
        ],
      ),
    );
  }

  List<Widget> _getChildren(BuildContext ctx) {
    List<Widget> children = [];
    for (int i = 0; i < navList.length; i++) {
      children.add(GestureDetector(
          onTap: () async {
            if (i == 0) {
              tokenManager.setToken('adshjfhkljsadhflkj');
              Navigator.pushNamed(ctx, '/house');
            }
            if (i == 1) {
              String token = await tokenManager.getToken();
              print(token);
            }
            if (i == 2) {
              tokenManager.removeToken();
            }

            // ScaffoldMessenger.of(ctx).showSnackBar(SnackBar(
            //     content: Text('我通知你'), duration: Duration(seconds: 1)));
            // PromptAction.info('成功');
            // 跳转页面  命名路由跳转  需要配合路由表
            // Navigator.pushNamed(context, '/home');
          },
          child: Column(children: [
            Image.asset(
              navList[i]['icon'],
              width: 35,
            ),
            Text(navList[i]['title'])
          ])));
    }
    return children;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(vertical: 10),
      padding: const EdgeInsets.all(10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Row(
          children: _getChildren(context),
          mainAxisAlignment: MainAxisAlignment.spaceAround),
    );
  }
}
